function showRoadSectionSearch() {
	window.location.href = "showRoadSectionSearch.do";
}

function ajaxFindRoadSectionSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxRoadSectionSearchList.do",
		data : {
			sectionnum:$("#txtSectionnum").val(),
			sectionname:$("#txtSectionname").val(),
			roadcode:$("#txtRoadcode").val(),
			organizationid:$("#txtOrganizationid").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listRoadSectionBox").html(msg);
		}

	});
}

function ajaxShowRoadSectionEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowRoadSectionEdit.do",
		data:{roadSectionId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 850,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveRoadSection(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxShowRoadSectionView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowRoadSectionView.do",
		data:{roadSectionId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 800,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxSaveRoadSection(objDialog) {
	roadSectionValidate();
	if ($("#frmRoadSection").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveRoadSection.do",
				success: function (msg) {
					clearInput("#sltRoadSection");
					ajaxFindRoadSectionSearchList();
					showMessageDialog("提示","路段信息保存成功。",null,dialogType.info);
				}
		};
		$("#frmRoadSection").ajaxSubmit(options);
	}
}

function ajaxDeleteRoadSectionById(id) {
	var roadSectionIds="";
	var sltRS = $("#listRoadSectionList tbody input:checked").length;
	if(id==null){
		$("#listRoadSectionList tbody input:checked").each(function(){ 
			roadSectionIds += $(this).val()+";";
		});
		if(sltRS == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			roadSectionIds = roadSectionIds.substring(0, roadSectionIds.length-1);
		} 
	}else{
		roadSectionIds=id;
		sltRS = 1;
	}
	if( roadSectionIds!=null){
		showMessageDialog("删除路段信息","确定要删除所选"+sltRS+"条路段信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteRoadSectionByIds.do",
				data:{roadSectionIds:roadSectionIds},
				success:function(msg){
					ajaxFindRoadSectionSearchList();
					showMessageDialog("提示","路段信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function roadSectionValidate(){
	$.validator.addMethod("compare",function(startmeter,element,endmeter){
		return $('#endmeter').val() >= $('#startmeter').val();
	},$.validator.format("起始米数必须不大于结束米数！"));
	$("#frmRoadSection").validate({
		errorLabelContainer: $("#infoRoadSection"),
		rules : {
			sectionname : {
				required :true				
			},
			sectionnum : {
				required :true,
				minlength:4,
			},
			roadcode : {
				required :false,
				minlength:5,
			},
			organizationid : {
				required :true,	
				minlength:12,
			},
			admindivision : {
				required :false,	
				minlength:6,
			},
			startmeter : {
				required :true,
				compare:["0","999"]
			},
			endmeter : {
				required :true,
			}
		},
		messages : {
			sectionname : {
				required :"请输入路段名称！"
			},
			sectionnum : {
				required :"请输入路段编号！",
				minlength:"请输入4位路段编号！",
			},
			roadcode : {
				minlength:"请输入5位道路代码！",
			},
			organizationid : {
				required :"请输入管理部门编号！",
				minlength:"请输入12位管理部门编号！",
			},
			admindivision : {
				minlength:"请输入6位行政区划！",
			},
			startmeter : {
				required :"请输入起始米数！",
			},
			endmeter : {
				required :"请输入结束米数！",
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}
